package mylibrary.rmi;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Person_Stub implements Person{
	
	Socket socket;
	
	public Person_Stub() throws UnknownHostException, IOException {
		socket = new Socket("localhost", 9000);
	}

	public int getAge() throws Exception {
		ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
		outStream.writeObject("age");
		outStream.flush();
		
		ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream());
		return inStream.readInt();
	}

	public String getName() throws Exception {

		ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
		outStream.writeObject("name");
		outStream.flush();
		
		ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream());
		return (String) inStream.readObject();
	
	}
}
